package com.ihr360.payroll.model.dto.salary.convertor;

import com.google.common.collect.Lists;
import com.ihr360.commons.lang.CollectionUtils;
import com.ihr360.commons.model.IConvertor;
import com.ihr360.payroll.entity.staff.StaffPayrollInfoJournalEntity;
import com.ihr360.payroll.model.dto.staff.StaffPayrollInfoJournal;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author richey
 */
@Component
public class StaffPayrollInfoJournalConvertor implements IConvertor<StaffPayrollInfoJournalEntity, StaffPayrollInfoJournal> {
    @Override
    public StaffPayrollInfoJournal convertEntityToDto(StaffPayrollInfoJournalEntity entity) {
        StaffPayrollInfoJournal dto = new StaffPayrollInfoJournal();
        BeanUtils.copyProperties(entity, dto);
        return dto;
    }

    @Override
    public StaffPayrollInfoJournalEntity convertDtoToEntity(StaffPayrollInfoJournal dto) {

        if (dto == null) {
            return null;
        }
        StaffPayrollInfoJournalEntity journalEntity = new StaffPayrollInfoJournalEntity();
        BeanUtils.copyProperties(dto, journalEntity);
        return journalEntity;
    }

    public List<StaffPayrollInfoJournalEntity> convertDtosToEntities(List<StaffPayrollInfoJournal> dtos) {
        if (CollectionUtils.isEmpty(dtos)) {
            return Lists.newArrayList();
        }
        List<StaffPayrollInfoJournalEntity> entities = Lists.newArrayListWithCapacity(dtos.size());
        dtos.forEach(dto -> {
            entities.add(convertDtoToEntity(dto));
        });
        return entities;
    }

    public List<StaffPayrollInfoJournal> convertEntitiesToDtos(List<StaffPayrollInfoJournalEntity> entities) {
        if (CollectionUtils.isEmpty(entities)) {
            return Lists.newArrayList();
        }
        List<StaffPayrollInfoJournal> dtos = Lists.newArrayListWithCapacity(entities.size());
        entities.forEach(entity -> {
            dtos.add(convertEntityToDto(entity));
        });
        return dtos;
    }


}
